package com.xtaller.sdboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xtaller.sdboot.entity.IamRole;
import com.xtaller.sdboot.mapper.IamRoleMapper;
import com.xtaller.sdboot.service.IamRoleService;
import com.xtaller.sdboot.core.base.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.stereotype.Service;

/** 
* 代码生成 
* @author: Taller  
* @date: 2020-02-07 15:56:30
* @Description: 用户角色服务实现 
*/ 
@Service 
@Slf4j
public class IamRoleServiceImpl extends BaseServiceImpl<IamRoleMapper, IamRole> implements IamRoleService {
    /**
     * 设置默认角色
     * */
    @Override
    public boolean initDefault(IamRole role) {
        if(role.getIsDefault() == 1){
            // 清空
            var qw = new QueryWrapper<IamRole>();
            qw.lambda().eq(IamRole::getIsDefault, 1);
            var model = new IamRole();
            model.setIsDefault(0);
            this.update(model, qw);
            model.setIsDefault(1);
            model.setId(role.getId());
            this.update(model);
        }
        return false;
    }


}
